<?php

namespace App\Http\Controllers\Home;

use App\Http\Controllers\Core\BaseController;
use App\Models\Resume;
use App\User;
use Illuminate\Support\Facades\Input;
use App\Models\Member;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class ResumeController extends BaseController
{
    public function __construct()
    {
        $this->middleware('auth');
    }

    public function index()
    {
        $user = Auth::user();
        $education = getEducationData();
        $operation = getOperationData();
        $vocation = getVocationData(1);
        $industry = getIndustryData();
        $jobs = Resume::get();
        return view('resume.index', compact('user', 'education', 'operation', 'vocation', 'industry','jobs'));
    }

    public function edit(Request $request, $id)
    {
        if ($id == 0) {
            return $this->retJson(400, 'ID出错!');
        }
        $inputs = Input::all();
        $model = User::find($id);
        foreach ($inputs as $key => $input) {
            $model->$key = $input;
        }
        if ($model->save()) {
            return $this->retJson(200, '操作成功', []);
        }
    }

//    public function edit($id, Request $request)
//    {
//        //数据验证
//        echo $id;
//        dd($request->all());
//    }

    public function job(Request $request, $id)
    {
        $inputs = Input::all();
        if(isSet($inputs['id']) && $inputs['id']){
            $model = Resume::find($inputs['id']);
        }else{
            $model = new Resume();
        }
        $model->user_id = Auth::id();
        $model->company_name = $inputs['company'];
        $model->company_name = $inputs['company'];
        $model->vocation_name = $inputs['vocation_name'];
        $model->start_data = $inputs['start_data'];
        $model->end_data = $inputs['end_data'];
        $model->salary = $inputs['salary'];
        $model->content = $inputs['content'];
        if($model->save()){
            echo $this->retRequestJson(200,'操作成功');
        }else{
            echo $this->retRequestJson(400,'操作失败');
        }
        //return view('home.member.job');
    }

    public function basis()
    {
        $user = Auth::user();
        $education = getEducationData();
        $operation = getOperationData();
        $vocation = getVocationData();
        return view('resume.basis', compact('user', 'education', 'operation', 'vocation'));
    }
}